<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>couchdbkit.ext.pylons</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="couchdbkit-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="couchdbkit-module.html">Package&nbsp;couchdbkit</a> ::
        <a href="couchdbkit.ext-module.html">Package&nbsp;ext</a> ::
        Package&nbsp;pylons
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="couchdbkit.ext.pylons-module.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<!-- ==================== PACKAGE DESCRIPTION ==================== -->
<h1 class="epydoc">Package pylons</h1><p class="nomargin-top"><span class="codelink"><a href="couchdbkit.ext.pylons-pysrc.html">source&nbsp;code</a></span></p>
<pre class="literalblock">
Pylons extension to simplify using couchdbkit with pylons. This features the
following:
 * Simple configuration
 * Authentication
 * View synchronization
 * Testing

Configuration
-------------
Add this to your ini file:

couchdb.uri = http://localhost:5984
couchdb.dbname = mydbname
cookies.secret = randomuniquestringforauth

And this into environment.py:

from couchdbkit.ext.pylons import init_from_config
init_from_config(config)

Authentication
--------------
You first need to define a User model, add this into model/user.py:

from couchdbkit import StringProperty
from couchdbkit.ext.pylons.auth.model import User as UserBase

class User(UserBase):
    first_name = StringProperty()
    last_name = StringProperty()
    email = StringProperty()

Then add this into middleware.py:
from yourapp.model.user import User
from couchdbkit.ext.pylons.auth.basic import AuthBasicMiddleware
app = AuthBasicMiddleware(app, config, User)

NOTE: This authentication by default uses sha-256 hashing with a salt, the behaviour
can be changed by overriding methods.

Now we need the views required for authentication:
Create yourapp/_design/user/views/by_login/map.js and make it look like this:
function(doc) {
    if(doc.doc_type == &quot;User&quot;) {
        emit(doc.login, doc);
    }
}

And yourapp/_design/group/views/by_name/map.js:
function(doc) {
    if(doc.doc_type == &quot;Group&quot;) {
        emit(doc.name, doc);
    }
}

And yourapp/_design/group/views/show_permissions/map.js:
function(doc) {
    if (doc.doc_type == &quot;Group&quot;) {
        for (var i = 0; i &lt; doc.permissions.length; i++) {
            emit(doc.name, doc.permissions[i].name);
        }
    }
}

View synchronization
--------------------
This will sync yourapp/_design to the CouchDB database described in the config.
couchdbkit has a built-in syncdb command that will automatically sync it. We
need to open up setup.py and add the command there as an entry point:

[paste.paster_command]
syncdb = couchdbkit.ext.pylons.commands:SyncDbCommand

And then add 'couchdbkit' to paster_plugins in the same file.

Syncing the database is then as simple as: paster syncdb /path/to/config.ini

Testing
-------
This will make it easier to create unit and functional tests that use couchdb
and load fixtures, this is not done yet and is TBC.

</pre>

<!-- ==================== SUBMODULES ==================== -->
<a name="section-Submodules"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Submodules</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Submodules"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
  <tr><td class="summary">
  <ul class="nomargin">
    <li> <strong class="uidlink"><a href="couchdbkit.ext.pylons.commands-module.html">couchdbkit.ext.pylons.commands</a></strong>    </li>
    <li> <strong class="uidlink"><a href="couchdbkit.ext.pylons.db-module.html">couchdbkit.ext.pylons.db</a></strong>    </li>
    <li> <strong class="uidlink"><a href="couchdbkit.ext.pylons.test-module.html">couchdbkit.ext.pylons.test</a></strong>    </li>
  </ul></td></tr>
</table>

<br />
<!-- ==================== VARIABLES ==================== -->
<a name="section-Variables"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Variables</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Variables"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
        <a name="__package__"></a><span class="summary-name">__package__</span> = <code title="'couchdbkit.ext.pylons'"><code class="variable-quote">'</code><code class="variable-string">couchdbkit.ext.pylons</code><code class="variable-quote">'</code></code>
    </td>
  </tr>
</table>
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="couchdbkit-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Fri May  4 11:48:40 2012
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
